﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pasteles.DataBase;

namespace Pasteles
{
    public partial class DonDatHangForm : Form
    {
        Connection cn = new Connection("config.xml");
        DataTable dbt_Donhang;
        DataView dbv_Donhang;
        string maDonHang;
        public DonDatHangForm()
        {
            InitializeComponent();
            this.load_Form();
        }
        private void load_Form()
        {
            dbt_Donhang = cn.excecuteQueryToDataTable("Select * from don_dat_hang where MA_DON_DAT_HANG >=2 order by NGAY_GIAO_HANG DESC;");
            dbv_Donhang = new DataView(dbt_Donhang);
            listBox1.DataSource = dbt_Donhang;
            listBox1.DisplayMember = dbt_Donhang.Columns[2].ColumnName;
            listBox1.ValueMember = dbt_Donhang.Columns[0].ColumnName;
            comboBox1.Text = "";
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void DonDatHangForm_Load(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                maDonHang = listBox1.SelectedValue.ToString();
            }
            comboBox1.Text = maDonHang.ToString();
            textBox2.Text = dbt_Donhang.Rows[listBox1.SelectedIndex][1].ToString();
            textBox4.Text = dbt_Donhang.Rows[listBox1.SelectedIndex][3].ToString();
            textBox6.Text = dbt_Donhang.Rows[listBox1.SelectedIndex][4].ToString();
            textBox5.Text = dbt_Donhang.Rows[listBox1.SelectedIndex][5].ToString();
            textBox1.Text = (long.Parse(textBox5.Text) - long.Parse(textBox6.Text)).ToString();
        }
    }
}
